package com.travel.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.travel.system.entity.Attractions;
import com.travel.system.mapper.AttractionsMapper;
import com.travel.system.service.AttractionsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class AttractionsServiceImpl extends ServiceImpl<AttractionsMapper, Attractions> implements AttractionsService {


    @Override
    public List<Attractions> getFive() {
        List<Attractions> list = this.list(new LambdaQueryWrapper<Attractions>().orderByDesc(Attractions::getId));
        List<Attractions> res = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(list)) {
            res = list.stream().limit(5).collect(Collectors.toList());
        }
        return res;
    }
}
